home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: news.sprintlink.net!mv!usenet
- From: ENGR@GSSI.MV.COM (Michael Furman)
- Subject: Re: Help -- Problem with Protected Class in Borland 4.5
- Message-ID: <DnJuwx.9to@mv.mv.com>
- Mime-Version: 1.0
- Organization: GSSI
- Date: Thu, 29 Feb 1996 18:19:44 GMT
- References: <4h4fgt$ina@sulawesi.lerc.nasa.gov>
- X-Newsreader: WinVN 0.93.10
- X-Nntp-Posting-Host: gssi.mv.com
-
- In article <4h4fgt$ina@sulawesi.lerc.nasa.gov>, edfollo@lovage.lerc.nasa.gov
- says...
- >
- >
- >I'm using Borland C++ 4.5, trying to create either a DOS target or a EasyWin
- >target. I cannot get the following code to compile:
- >
- >#include <iostream.h>
- >
- >class BaseClass
- >{
- > public:
- > int a;
- > protected:
- > int b;
- >};
- >
- >
- >class UpperClass : public BaseClass
- >{
- > public:
- > void print_a() {cout << "\na = " << a;}
- > void print_b() {cout << "\nb = " << b;}
- >};
- >
- >void main()
- >{
- > UpperClass x;
- >
- > x.a = 1;
- > x.b = 2;
- >
- > x.print_a();
- > x.print_b();
- >
- >}
- >
- >
- >The error I get is:
- >
- >'BaseClass::b' is not accessible in function main()
- >
- >
- >The code works if I comment out protected. What's wrong here?
- >
-
- You explicitly forbid access to "b" by declareing it as protected! So what
- do you want?
- "public" means that you can access member from everywere;
- "private" - only from member functions of this class;
- "protected" - from member functuons of this class and derived classes
- (if they are not derived "privately") - but not from other functions
- like main.
-
-
- --
- <<< If you received it by E-mail: it is a copy of post to the newsgroup >>>
- ---------------------------------------------------------------
- Michael Furman, (603)893-1109
- Geophysical Survey Systems, Inc. fax:(603)889-3984
- 13 Klein Drive - P.O. Box 97 engr@gssi.mv.com
- North Salem, NH 03073-0097 71543.1334@compuserve.com
- ---------------------------------------------------------------
-
-